package cn.com.open.opensaas.scoreservice.domain.TestPaperModel;

import cn.com.open.opensaas.scoreservice.util.AbstractDomain;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by liyun on 2017/4/11.
 */
public class SectionCount extends AbstractDomain {
	String questionTypeId;
	String questionTypeName;
	Integer itemSize;
	//用于计算每个section中item得分总和
	Double sectionScore = 0.0;
	//用于统计每个section中item回答正确数量
    Integer correctCount = 0;
	//用于统计每个section中item回答错误数量
    Integer wrongCount = 0;
	//用于统计每个section中item未做答数量
    Integer unAnswerCount = 0;
    //用于标识是否做答 false=未做答 true=已做答
    Boolean unAnswerFlag = false;
    
	public Double getSectionScore() {
		return sectionScore;
	}
	public void setSectionScore(Double sectionScore) {
		this.sectionScore += sectionScore;
	}
	public Integer getCorrectCount() {
		return correctCount;
	}
	public void setCorrectCount(Integer correctCount) {
		this.correctCount += correctCount;
	}
	public Integer getWrongCount() {
		return wrongCount;
	}
	public void setWrongCount(Integer wrongCount) {
		this.wrongCount += wrongCount;
	}
	public Integer getUnAnswerCount() {
		return unAnswerCount;
	}
	public void setUnAnswerCount(Integer unAnswerCount) {
		this.unAnswerCount += unAnswerCount;
	}
	public Boolean getUnAnswerFlag() {
		return unAnswerFlag;
	}
	public void setUnAnswerFlag(Boolean unAnswerFlag) {
		this.unAnswerFlag = unAnswerFlag;
	}
	public String getQuestionTypeId() {
		return questionTypeId;
	}
	public void setQuestionTypeId(String questionTypeId) {
		this.questionTypeId = questionTypeId;
	}
	public String getQuestionTypeName() {
		return questionTypeName;
	}
	public void setQuestionTypeName(String questionTypeName) {
		this.questionTypeName = questionTypeName;
	}
	public Integer getItemSize() {
		return itemSize;
	}
	public void setItemSize(Integer itemSize) {
		this.itemSize = itemSize;
	}
	
	//将section各统计项置为0
	public void resetSectionCount(){
		this.sectionScore = 0.0;
		this.correctCount = 0;
		this.wrongCount = 0;
		this.unAnswerCount = 0;
	}
	
	//拼接statMap并返回
	public Map<String,Object> getStatMap(){
		//用于存储每个section的stat数据
    	Map<String,Object> statMap = new HashMap<String,Object>();
    	//存储statMap数据
    	statMap.put("QuestionTypeId", questionTypeId);
    	statMap.put("QuestionTypeName", questionTypeName);
    	statMap.put("TotalCount", itemSize);
    	statMap.put("CorrectCount", correctCount);
    	statMap.put("WrongCount", wrongCount);
    	statMap.put("UnanswerCount", unAnswerCount);
    	statMap.put("CorrectRate", getCorrectRate(4));
    	statMap.put("Score", sectionScore);
    	return statMap;
	}
	
	//计算正确率 decimalSize 小数位数
	public Double getCorrectRate(Integer decimalSize){
		double correctRate = correctCount*1.0/itemSize;
		correctRate = Double.parseDouble(String.format("%."+decimalSize+"f",correctRate));
		return correctRate;
	}
}
